<!DOCTYPE html>
<html>
<head>
    <title>添加影片</title>
    <link rel="stylesheet" type="text/css" href="__STATIC__/plugins/layui/css/layui.css">
    <script type="text/javascript" src="__STATIC__/plugins/layui/layui.js"></script>
</head>
<body style="padding: 10px;">
<form class="layui-form">
    <input type="hidden" name="id" value="{$data.item.id}">
    <div class="layui-form-item">
        <label class="layui-form-label">影片名称</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="title" value="{$data.item.title}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">频道</label>
        <div class="layui-input-inline">
            <select name="channel_id">
                <option value="0">请选择</option>
                {volist name='data.channel' id='vo_channel'}
                <option value="{$vo_channel.id}" {$vo_channel.id==$data.item.channel_id?'selected':''}>{$vo_channel.title}</option>
                {/volist}
            </select>
        </div>

        <label class="layui-form-label">资费</label>
        <div class="layui-input-inline">
            <select name="charge_id">
                <option value="0">请选择</option>
                {volist name='data.charge' id='vo_charge'}
                <option value="{$vo_charge.id}" {$vo_charge.id==$data.item.charge_id?'selected':''}>{$vo_charge.title}</option>
                {/volist}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">地区</label>
        <div class="layui-input-inline">
            <select name="area_id">
                <option value="0">请选择</option>
                {volist name='data.area' id='vo_area'}
                <option value="{$vo_area.id}" {$vo_area.id==$data.item.area_id?'selected':''}>{$vo_area.title}</option>
                {/volist}
            </select>
        </div>
        <label class="layui-form-label">&nbsp;</label>
        <div class="layui-input-inline">
            <button class="layui-btn layui-btn-sm" onclick="return false;" id="upload_img"><i class="layui-icon">&#xe67c;</i>上传图片</button>
            <img id="pre_img" src="{$data.item.img?$data.item.img:''}" style="height: 30px;">
            <input type="hidden" name="img" value="{$data.item.img}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">影片地址</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="url" value="{$data.item.url}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">关键字</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="keywords" value="{$data.item.keywords}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="desc" value="{$data.item.desc}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-inline">
            <input type="checkbox" layui-skin="primary" name="status" title="发布" {$data.item.status?'checked':''} value="1">
        </div>
    </div>
</form>
<div class="layui-form-item">
    <div class="layui-input-block">
        <button class="layui-btn" onclick="save()">保存</button>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
    layui.use(['form','layer','upload'],function(){
        $ = layui.jquery;
        var form = layui.form;
        layer = layui.layer;

        var upload = layui.upload;

        //执行实例
        var uploadInst = upload.render({
            elem: '#upload_img' //绑定元素
            ,url: "{:url('admins/Video/upload_img')}" //上传接口
            ,accept:'images'
            ,done: function(res){
                // console.log(res);
                //上传完毕回调
                $('#pre_img').attr('src',res.msg);
                $('input[name="img"]').val(res.msg);
            }
            ,error: function(){
                //请求异常回调
            }
        });
    });

    // 保存
    function save(){
        var title = $.trim($('input[name="title"]').val());
        var url = $.trim($('input[name="url"]').val());
        if(title == ''){
            layer.msg('请输入影片名称',{'icon':2,'anim':6});
            return;
        }
        if(url == ''){
            layer.msg('请输入影片地址',{'icon':2,'anim':6});
            return;
        }
        $.post("{:url('admins/Video/save')}",$('form').serialize(),function(res){
            if(res.code>0){
                layer.msg(res.msg,{'icon':2,'anim':2});
            }else{
                layer.msg(res.msg,{'icon':1});
                setTimeout(function(){parent.window.location.reload();},500);
            }
        },'json');
    }
</script>